<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>测试reactive</h2>
      <p id="name"></p>
      <p id="age"></p>
      <p id="sex"></p>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.47/vue.global.js"></script>
    <script>
      const { reactive, effect } = Vue
      // effect: 用来注册副作用函数的函数
      // 定义reactive对象

      const state = reactive({
        name: 'tom',
        age: 12
      })
      effect(function effect1() {
        console.log('name effect')
        document.getElementById('name').innerHTML = state.name
      })
      effect(function effect2() {
        console.log('age effect')
        document.getElementById('age').innerHTML = state.age
      })
      effect(function effect3() {
        console.log('sex effect')
        document.getElementById('sex').innerHTML = state.sex
      })

      setTimeout(() => {
        // state.name = 'abc'
        // state.age = 2
        // state.sex = '女'
        // delete state.name
      }, 2000);

    </script>
  </body>
</html>
